package com.lvyq.javaprint.util;

import com.lvyq.javaprint.MainWinApplication;
import com.lvyq.javaprint.view.index.OpinionView;
import com.lvyq.javaprint.view.index.ProxySettingView;
import javafx.animation.FadeTransition;
import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.ScrollPane;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.util.Duration;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;

/**
 * @author lvyq
 * @version 1.0
 * Create by 2024-05-14 14:39
 */
public class CommonUtils {

    /**
     * @description 读取图片
     * @author lvyq
     * @param[1] path
     * @throws
     * @return Image
     * @time 2024-04-24 17:33
     */
    public static java.awt.Image getImage(String path){
        URL url= MainWinApplication.class.getClassLoader().getResource(path);
        BufferedImage image=null;
        try {
            image= ImageIO.read(url);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return image;
    }



 /** 统一点击跳转
  * @description
  * @author lvyq
  * @param[1] proxyBut  代理按钮
  * @param[2] opinionBut 建议按钮
  * @param[3] scrollPane 视图
  * @param[5] printView 打印列表视图
  * @param[6] viewTitle title名称
  * @throws

  * @time 2025-08-15 14:00
  */
    public static void scrollPaneButFunction(Button proxyBut,Button opinionBut, ScrollPane scrollPane,VBox printView, Button viewTitle){

        //代理视图
        BorderPane  proxyView= ProxySettingView.createProxyBoxView(scrollPane,printView);
        //反馈视图
        BorderPane opinionView = OpinionView.createOpinionBoxView();
        Runnable switchToPrintView = () -> {
            viewTitle.setText("打印服务列表");
            scrollPane.setContent(printView);
        };
        // 代理按钮事件
        proxyBut.setOnMouseClicked(event -> {

            if (scrollPane.getContent() != proxyView) {
                viewTitle.setText("代理设置");
                //强制刷新
                ProxySettingView.createProxyBoxView(scrollPane,printView);
                scrollPane.setContent(proxyView);

            } else {
                switchToPrintView.run();
            }
        });

        // 反馈按钮事件
        opinionBut.setOnMouseClicked(event -> {
            if (scrollPane.getContent() != opinionView) {
                viewTitle.setText("意见反馈");
                scrollPane.setContent(opinionView);
            } else {
                switchToPrintView.run();
            }
        });
    }


}
